﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UcAsp.Models;

namespace UcAsp.Controllers
{
    public class TeachManagerController : Controller
    {
        //
        // GET: /TeachManager/
        private UcAspNetEntities entities = new UcAspNetEntities();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Teach()
        {
            if (Session["Info"] == null)
            {

                return Redirect("/adminlogin/login");
            }
            else
            {
                if (Session["Info"].ToString() != "Admin")
                {
                    return Redirect("/adminlogin/login");
                }
            }
            List<Articles> list = new List<Articles>();
            var query = from c in entities.Articless
                        where c.CategorieID==10
                        orderby c.Rate descending
                        select c;

            int pagesize = 20;
            int pageindex = 0;
            if (Request.QueryString["page"] != null)
            {
                pageindex = int.Parse(Request.QueryString["page"].ToString()) - 1;
            }
            ViewData["PageIndex"] = pageindex + 1;
            ViewData["PageCount"] = (query.Count() + 19) / 20;

            list = query.Skip(pageindex * pagesize).ToList<Articles>().Take(pagesize).ToList();




            return View(list);
            
        }
        public ActionResult TeachWork()
        {
            if (Session["Info"] == null)
            {

                return Redirect("/adminlogin/login");
            }
            else
            {
                if (Session["Info"].ToString() != "Admin")
                {
                    return Redirect("/adminlogin/login");
                }
            }
            List<Articles> list = new List<Articles>();
            var query = from c in entities.Articless
                        join m in entities.Categoriess
                        on c.CategorieID equals m.ID
                        where m.ParentID == 21
                        orderby c.Rate descending
                        select c;

            int pagesize = 20;
            int pageindex = 0;
            if (Request.QueryString["page"] != null)
            {
                pageindex = int.Parse(Request.QueryString["page"].ToString()) - 1;
            }
            ViewData["PageIndex"] = pageindex + 1;
            ViewData["PageCount"] = (query.Count() + 19) / 20;

            list = query.Skip(pageindex * pagesize).ToList<Articles>().Take(pagesize).ToList();




            return View(list);
           
        }
        public ActionResult CourseManager()
        {
            if (Session["Info"] == null)
            {

                return Redirect("/adminlogin/login");
            }
            else
            {
                if (Session["Info"].ToString() != "Admin")
                {
                    return Redirect("/adminlogin/login");
                }
            }
            List<Articles> list = new List<Articles>();
            var query = from c in entities.Articless
                        join m in entities.Categoriess
                        on c.CategorieID equals m.ID
                        where m.ParentID == 11
                        orderby c.Rate descending
                        select c;

            int pagesize = 20;
            int pageindex = 0;
            if (Request.QueryString["page"] != null)
            {
                pageindex = int.Parse(Request.QueryString["page"].ToString()) - 1;
            }
            ViewData["PageIndex"] = pageindex + 1;
            ViewData["PageCount"] = (query.Count() + 19) / 20;

            list = query.Skip(pageindex * pagesize).ToList<Articles>().Take(pagesize).ToList();




            return View(list);
        }
    }
}
